<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <input type="text" placeholder="请输入数字" id="num1">
    <input type="text" placeholder="请输入数字" id="num2">
    <input type="button" value="最大公约数" id="btn">
    <p id="p"></p>
</body>
<script>
    var btn = document.getElementById('btn');
    var p = document.getElementById('p');
    btn.onclick = function () {
        var num1 = document.getElementById('num1').value * 1;
        var num2 = document.getElementById('num2').value * 1;
        var min = num1 < num2 ? num1 : num2;
        for (var i = min;i >= 1;i--) {
            // console.log(i);
            if ((num1 % i == 0) && (num2 % i == 0)) {
                p.innerHTML = '最大公约数为' + i;
                break;
            }
        }
    }
</script>

</html>